package com.xveshe.admin.service.impl;

import java.util.List;

import com.xveshe.admin.domain.XsglXsxx;
import com.xveshe.common.utils.DateUtils;
import com.xveshe.common.utils.SecurityUtils;
import com.xveshe.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xveshe.admin.mapper.XsglGxrwMapper;
import com.xveshe.admin.domain.XsglGxrw;
import com.xveshe.admin.service.IXsglGxrwService;

/**
 * 岗训任务收发Service业务层处理
 *
 * @author 葛亚松
 * @date 2024-11-18
 */
@Service
public class XsglGxrwServiceImpl implements IXsglGxrwService
{
    @Autowired
    private XsglGxrwMapper xsglGxrwMapper;

    /**
     * 查询岗训任务收发
     *
     * @param id 岗训任务收发主键
     * @return 岗训任务收发
     */
    @Override
    public XsglGxrw selectXsglGxrwById(String id)
    {
        return xsglGxrwMapper.selectXsglGxrwById(id);
    }

    /**
     * 查询岗训任务收发列表
     *
     * @param xsglGxrw 岗训任务收发
     * @return 岗训任务收发
     */
    @Override
    public List<XsglGxrw> selectXsglGxrwList(XsglGxrw xsglGxrw)
    {
        if(!(SecurityUtils.getUsername().equals("admin")||SecurityUtils.hasRole("guanli")
                ||SecurityUtils.getUsername().contains("x"))){
            xsglGxrw.setGxrwQyds(SecurityUtils.getUsername());
            xsglGxrw.setGxrwDs(SecurityUtils.getUsername());
        }
        return xsglGxrwMapper.selectXsglGxrwList(xsglGxrw);
    }

    /**
     * 新增岗训任务收发
     *
     * @param xsglGxrw 岗训任务收发
     * @return 结果
     */
    @Override
    public int insertXsglGxrw(XsglGxrw xsglGxrw)
    {
        xsglGxrw.setId(UUID.randomUUID().toString());
        //获取用户账号xsglXslb.setCreator(SecurityUtils.getUsername());
        //获取用户昵称
        xsglGxrw.setGxrwLcjd("0");
        xsglGxrw.setCreator(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglGxrw.setGxrwDs(SecurityUtils.getUsername());
        xsglGxrw.setCreatedate(DateUtils.getNowDate());
        return xsglGxrwMapper.insertXsglGxrw(xsglGxrw);
    }

    /**
     * 修改岗训任务收发
     *
     * @param xsglGxrw 岗训任务收发
     * @return 结果
     */
    @Override
    public int updateXsglGxrw(XsglGxrw xsglGxrw)
    {
        xsglGxrw.setLastmodifier(SecurityUtils.getLoginUser().getUser().getNickName());
        //xsglGxrw.setGxrwQyds(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglGxrw.setLastmodifieddate(DateUtils.getNowDate());
        return xsglGxrwMapper.updateXsglGxrw(xsglGxrw);
    }

    /**
     * 批量删除岗训任务收发
     *
     * @param ids 需要删除的岗训任务收发主键
     * @return 结果
     */
    @Override
    public int deleteXsglGxrwByIds(String[] ids)
    {
        return xsglGxrwMapper.deleteXsglGxrwByIds(ids);
    }

    /**
     * 删除岗训任务收发信息
     *
     * @param id 岗训任务收发主键
     * @return 结果
     */
    @Override
    public int deleteXsglGxrwById(String id)
    {
        return xsglGxrwMapper.deleteXsglGxrwById(id);
    }
}
